package cn.itcast.service.impl;
import cn.itcast.dao.PermissionDao;
import cn.itcast.dao.UserDao;
import cn.itcast.entity.PageResult;
import cn.itcast.entity.QueryPageBean;
import cn.itcast.pojo.Permission;
import cn.itcast.pojo.User;
import cn.itcast.service.PermissionService;
import cn.itcast.service.UserService;
import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.stream.Stream;

@Service
@Transactional
public class PermissionServiceImpl implements PermissionService {
 @Autowired
 private PermissionDao permissionDao;

    /**
     * 添加权限
     * @param permission
     */
    @Override
    public void add(Permission permission) {
     permissionDao.add(permission);
    }




    public PageResult selectByCondition(QueryPageBean queryPageBean) {
        PageHelper.startPage(queryPageBean.getCurrentPage(),queryPageBean.getPageSize());
        Page<Permission> page = permissionDao.selectByCondition(queryPageBean.getQueryString());
        return new PageResult(page.getTotal(),page.getResult());
    }


    /**
     * 单个查询回显
     * @param id
     * @return
     */
    @Override
    public Permission findById(Integer id) {

        return permissionDao.findById(id);
    }

    /**
     * 删除权限列表
     * @param id
     */
    @Override
    public void deleteById(Integer id) {
       permissionDao.deleteById(id);
    }

    /**
     * 修改权限列表
     * @param permission
     */
    @Override
    public void update(Permission permission) {
         permissionDao.update(permission);
    }

    @Override
    public List<Permission> findAll() {
        return permissionDao.findAll();
    }

    @Override
    public List<Permission> findByRid(Integer rid) {
        return permissionDao.findByRid(rid);
    }

    @Override
    public List<Permission> findMenuAssociation(Integer menusIds) {
        return permissionDao.findMenuAssociation(menusIds);
    }


}
